package com.xuanmiao.smsback.service.platform.operator.impl;

import com.xuanmiao.smsback.dao.model.PriceHistoryInfoDO;
import com.xuanmiao.smsback.domain.qo.BusinessPriceInfoQO;
import com.panshi.hujin2.base.common.util.DozerUtils;
import com.panshi.hujin2.base.domain.page.Page;
import com.xuanmiao.smsback.dao.mapper.BusinessPriceInfoMapper;
import com.xuanmiao.smsback.dao.model.BusinessPriceInfoDO;

import com.xuanmiao.smsback.domain.qo.PriceHistoryInfoQO;
import com.xuanmiao.smsback.model.BusinessPriceInfoBO;
import com.xuanmiao.smsback.service.platform.operator.BusinessPriceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;


@Service
public class BusinessPriceInfoServiceImpl implements BusinessPriceInfoService {
    @Autowired
    private BusinessPriceInfoMapper businessPriceInfoMapper;
    @Override
    public List<BusinessPriceInfoBO> getList(BusinessPriceInfoQO businessPriceInfoQO) {
        if(businessPriceInfoQO == null){
            businessPriceInfoQO = new BusinessPriceInfoQO();
        }
        //获取数量
        Integer count = businessPriceInfoMapper.count(businessPriceInfoQO);
        Page page = businessPriceInfoQO.getPage();
        //设置总记录数
        page.setTotalNumber(count);
        List<BusinessPriceInfoDO> businessPriceInfoDO = businessPriceInfoMapper.queryBusinessPriceInfo(businessPriceInfoQO);
        if(businessPriceInfoDO!=null && businessPriceInfoDO.size()>0){
            List<BusinessPriceInfoBO> areContactInfoBO = DozerUtils.convertList(businessPriceInfoDO, BusinessPriceInfoBO.class);

            return areContactInfoBO;
                    //DozerUtils.convertList(areContactInfoMapper.query(areContactInfoQO),BusinessPriceInfoBO.class);
        }
        return Collections.emptyList();


    }

    @Override
    public BusinessPriceInfoBO getById(Integer id) {
        return DozerUtils.convert(businessPriceInfoMapper.getById(id),BusinessPriceInfoBO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(BusinessPriceInfoBO businessPriceInfoBO) {
        businessPriceInfoMapper.update(DozerUtils.convert(businessPriceInfoBO,BusinessPriceInfoDO.class));
        businessPriceInfoMapper.updateCreditLimit(DozerUtils.convert(businessPriceInfoBO,BusinessPriceInfoDO.class));
        businessPriceInfoMapper.addHistory(DozerUtils.convert(businessPriceInfoBO, BusinessPriceInfoDO.class));
    }

    @Override
    public List<BusinessPriceInfoBO> getHistory(PriceHistoryInfoQO priceHistoryInfoQO) {
        if(priceHistoryInfoQO == null){
            priceHistoryInfoQO = new PriceHistoryInfoQO();
        }
        //获取数量
        Integer count = businessPriceInfoMapper.countHistory(priceHistoryInfoQO);
        Page page = priceHistoryInfoQO.getPage();
        //设置总记录数
        page.setTotalNumber(count);
        List<PriceHistoryInfoDO> businessPriceInfoDO = businessPriceInfoMapper.getHistoryById(priceHistoryInfoQO);
        if(businessPriceInfoDO!=null && businessPriceInfoDO.size()>0){
            List<BusinessPriceInfoBO> areContactInfoBO = DozerUtils.convertList(businessPriceInfoDO, BusinessPriceInfoBO.class);

            return areContactInfoBO;
            //DozerUtils.convertList(areContactInfoMapper.query(areContactInfoQO),BusinessPriceInfoBO.class);
        }
        return Collections.emptyList();

    }


}
